package com.wesley.netty.unpackage;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * CustomMessageEncoder
 *
 * @author WangPanYong
 * @since 2021/11/16 11:22
 */
public class CustomMessageEncoder extends MessageToByteEncoder<CustomMessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, CustomMessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println("MyMessageEncoder encode 方法被调用");
        out.writeInt(msg.getLen());
        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }

}
